﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KingRoad.EPM.SafetyManagementBLL.Domain;
using KingRoad.EPM.SafetyManagementEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.SafetyManagementDAL.ScmAssessmentitemsService;
using KingRoad.EPM.SafetyManagementDAL.ScmSafetyconstructiondicService;


namespace KingRoad.EPM.SafetyManagementBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/2/5 17:00:16
    /// </summary> 
    public class ScmAssessmentitemsUIRule
    {
        private readonly IScmAssessmentitemsService _scmAssessmentitemsService;
        private ScmSafetyconstructiondicUIRule _scmSafetyconstructiondicUIRule;

        public ScmAssessmentitemsUIRule()
        {

        }

        /// <summary> 
        /// construct function... 
        /// </summary> 
        public ScmAssessmentitemsUIRule(IScmAssessmentitemsService scmAssessmentitemsService)
        {
            _scmAssessmentitemsService = scmAssessmentitemsService;
        }

        /// <summary>
        /// 根据考核类型获取考核项目信息
        /// </summary>
        /// <param name="typeID">考核类型</param>
        /// <returns></returns>
        public List<ScmAssessmentitemsInfo> GetAssessmentitemsByType(string typeID)
        {
            string sql = " 1=1 ";
            if (typeID != "")
            {
                _scmSafetyconstructiondicUIRule = new ScmSafetyconstructiondicUIRule(new ScmSafetyconstructiondicService());
                var constructiondicList = _scmSafetyconstructiondicUIRule.GetSafetyconstructiondicByPID(typeID);
                string type = "";
                foreach (ScmSafetyconstructiondicInfo info in constructiondicList)
                {
                    type += "'" + info.Scd_ID + "',";
                }
                sql = "Ai_Type in (" + type.Trim(',') + ")";
            }
            var list = _scmAssessmentitemsService.GetEntityList(sql);
            return list;
        }

        /// <summary>
        /// 根据ID获取Info
        /// </summary>
        /// <param name="parentID">主键ID</param>
        /// <returns></returns>
        public ScmAssessmentitemsInfo GetInfoByID(Guid ID)
        {
            var list = _scmAssessmentitemsService.GetEntityById(ID);
            return list;
        }
        /// <summary>
        /// 根据条件查询List信息(分页)
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<ScmAssessmentitemsInfo> GetListForPage(int numCurrentPage, int numPerPage,
                                                                        string orderByField, out int totalRecord, string sqlCondition, string desc = "desc")
        {
            var list = _scmAssessmentitemsService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition,desc);
            return list;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool InsertEntity(ScmAssessmentitemsInfo entity)
        {
            var ret = _scmAssessmentitemsService.InsertEntity(entity);
            return ret > 0;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateEntity(ScmAssessmentitemsInfo entity)
        {
            var ret = _scmAssessmentitemsService.UpdateEntity(entity);
            return ret > 0;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteEntity(string id)
        {
            var ret = _scmAssessmentitemsService.DeleteEntityByStringID(id);
            return ret > 0;
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool DeleteEntityByMultiStringID(string ids)
        {
            var ret = 0;
            foreach (string id in ids.Split(','))
            {
                ret = _scmAssessmentitemsService.DeleteEntityByStringID(id);
            }
            return ret > 0;
        }
    }
}

